using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.ComponentModel;
using EcsSiteDSTableAdapters;

/// <summary>
/// Summary description for NewsBLL
/// </summary>
namespace SiteECSWeb
{
    [DataObject]
    public class TradAffectSubBLL
    {
        #region ClassConstructor
        public TradAffectSubBLL()
        {

        }
        #endregion

        private TradAffectSubTableAdapter _TradAffectSubAdapter = null;

        protected TradAffectSubTableAdapter TradAffectSubAdapter
        {
            get
            {
                if (_TradAffectSubAdapter == null)
                {
                    _TradAffectSubAdapter = new TradAffectSubTableAdapter();
                }
                return _TradAffectSubAdapter;
            }
        }

        #region SelectableTable
        public int GetTotalNumberOfTradAffectSub()
        {
            Nullable<int> totalNull = (Nullable<int>)TradAffectSubAdapter.TotalNumberOfTradAffectSub();
            return totalNull.GetValueOrDefault();
        }
        public int GetTotalNumberOfTradAffectSub(string FilterStr)
        {
            if (string.IsNullOrEmpty(FilterStr))
            {
                return GetTotalNumberOfTradAffectSub();
            }
            else
            {
                Nullable<int> totalNull = (Nullable<int>)TradAffectSubAdapter.
                TotalNumberOfTradAffectSubByFilterExp(FilterStr);
                return totalNull.GetValueOrDefault();
            }
        }
        [DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
        public EcsSiteDS.TradAffectSubDataTable GetTradAffectSubRowRank()
        {
            return TradAffectSubAdapter.GetTradAffectSubRowRankData();
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public EcsSiteDS.TradAffectSubDataTable GetTradAffectSubByTradAffectSubID(int TrdaffSub_Id)
        {
            return TradAffectSubAdapter.GetTradAffectSubDataByTradAffectSubID(TrdaffSub_Id);
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public EcsSiteDS.TradAffectSubDataTable GetTradAffectSubByRowRank(int RankID)
        {
            return TradAffectSubAdapter.GetTradAffectSubDataByRowRank(RankID);
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public EcsSiteDS.TradAffectSubDataTable GetTradAffectSubByCountryCode(string Cuntry_un2)
        {
            return TradAffectSubAdapter.GetTradAffectSubDataByCountryCode(Cuntry_un2);
        }
        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public EcsSiteDS.TradAffectSubDataTable GetTradAffectSubByCuntryEn(string CuntryEn)
        {
            return TradAffectSubAdapter.GetTradAffectSubDataByCuntryEn(CuntryEn);
        }
        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public EcsSiteDS.TradAffectSubDataTable GetTradAffectSubByGridPagesAndFilterExpression(int startRowIndex,
            int maximumRows, string sortExpression)
        {
            return TradAffectSubAdapter.GetTradAffectSubDataByGridPages(startRowIndex, maximumRows, sortExpression);
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public EcsSiteDS.TradAffectSubDataTable GetTradAffectSubByGridPagesAndFilterExpression(int startRowIndex, int maximumRows,
            string FilterStr, string sortExpression)
        {
            if (string.IsNullOrEmpty(FilterStr))
            {
                return
                    GetTradAffectSubByGridPagesAndFilterExpression(startRowIndex, maximumRows, sortExpression);
            }
            else
            {
                return TradAffectSubAdapter.GetTradAffectSubDataByGridPagesFilterExp
                    (startRowIndex, maximumRows, FilterStr, sortExpression);
            }
        }
        #endregion

        #region InsertableTable
        [DataObjectMethodAttribute(DataObjectMethodType.Insert, true)]
        public int AddTrdaffSub(string TrdaffSub_NameAr, string TrdaffSub_NameEn, DateTime TrdaffSub_Date,
            string TrdaffSub_Desc, string Cuntry_un2, string TrdaffSub_Path, bool? Publishing)
        {


            EcsSiteDS.TradAffectSubDataTable TradAffectSubtable = new EcsSiteDS.TradAffectSubDataTable();
            EcsSiteDS.TradAffectSubRow TradAffectSubRow = TradAffectSubtable.NewTradAffectSubRow();

            if (string.IsNullOrEmpty(TrdaffSub_NameEn)) TradAffectSubRow.SetTrdaffSub_NameEnNull(); else TradAffectSubRow.TrdaffSub_NameEn = TrdaffSub_NameEn;
            if (string.IsNullOrEmpty(TrdaffSub_Path )) TradAffectSubRow.SetTrdaffSub_PathNull(); else TradAffectSubRow.TrdaffSub_Path = TrdaffSub_Path;
            if (Publishing == null) TradAffectSubRow.SetPublishingNull(); else TradAffectSubRow.Publishing = Publishing.Value;

            TradAffectSubRow.TrdaffSub_NameAr = TrdaffSub_NameAr;
            TradAffectSubRow.TrdaffSub_Date = TrdaffSub_Date;

            TradAffectSubRow.TrdaffSub_Desc = TrdaffSub_Desc;
            TradAffectSubRow.Cuntry_un2 = Cuntry_un2;

            TradAffectSubtable.AddTradAffectSubRow(TradAffectSubRow);

            int rowsAffected = TradAffectSubAdapter.Update(TradAffectSubtable);

            return (rowsAffected == 1) ? TradAffectSubRow.TrdaffSub_Id : -1;
        }

        #endregion

        #region UpdatableTable
        [DataObjectMethodAttribute(DataObjectMethodType.Update, true)]
        public bool UpdateTrdaffSub(string TrdaffSub_NameAr, string TrdaffSub_NameEn, DateTime TrdaffSub_Date,
            string TrdaffSub_Desc, string Cuntry_un2, string TrdaffSub_Path, bool? Publishing, int TrdaffSub_Id)
        {
            EcsSiteDS.TradAffectSubDataTable TradAffectSubtable =
                TradAffectSubAdapter.GetTradAffectSubDataByTradAffectSubID(TrdaffSub_Id);

            if (TradAffectSubtable.Count == 0)
            {
                return false;
            }
            EcsSiteDS.TradAffectSubRow TradAffectSubRow = TradAffectSubtable[0];

            if (string.IsNullOrEmpty(TrdaffSub_NameEn)) TradAffectSubRow.SetTrdaffSub_NameEnNull(); else TradAffectSubRow.TrdaffSub_NameEn = TrdaffSub_NameEn;
            if (string.IsNullOrEmpty(TrdaffSub_Path)) TradAffectSubRow.SetTrdaffSub_PathNull(); else TradAffectSubRow.TrdaffSub_Path = TrdaffSub_Path;
            if (Publishing == null) TradAffectSubRow.SetPublishingNull(); else TradAffectSubRow.Publishing = Publishing.Value;

            TradAffectSubRow.TrdaffSub_NameAr = TrdaffSub_NameAr;
            TradAffectSubRow.TrdaffSub_Date = TrdaffSub_Date;

            TradAffectSubRow.TrdaffSub_Desc = TrdaffSub_Desc;
            TradAffectSubRow.Cuntry_un2 = Cuntry_un2;


            int roweffected = TradAffectSubAdapter.Update(TradAffectSubRow);
            return roweffected == 1;
        }
        #endregion

        #region DeletableTable
        [DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
        public bool DeleteTrdaffSub(int TrdaffSub_Id)
        {
            EcsSiteDS.TradAffectSubDataTable TradAffectSubtable =
               TradAffectSubAdapter.GetTradAffectSubDataByTradAffectSubID(TrdaffSub_Id);

            if (TradAffectSubtable.Count == 0)
            {
                return false;
            }
            EcsSiteDS.TradAffectSubRow TradAffectSubRow = TradAffectSubtable[0];
            if (!TradAffectSubRow.IsTrdaffSub_PathNull())
            {
                System.IO.File.Delete(HttpContext.Current.Server.MapPath(Globals.Settings.UploadInfo.RootAttachFolder
                       + TradAffectSubRow.TrdaffSub_Path));
            }
          
            int rowsAffected = TradAffectSubAdapter.Delete(TrdaffSub_Id);
            return rowsAffected == 1;
        }
        #endregion
    }
}
